#include <stdio.h>
#include <stdlib.h>



typedef struct node{
    int x;//非零项系数
    int y;//指数
    struct node* next;
}node;
typedef node* polynomiral;

polynomiral addPolynomiral(polynomiral p,polynomiral q);
polynomiral multiplicationPolynomiral(polynomiral p,polynomiral q);


void printPolynomiral(polynomiral list){
    polynomiral p=list->next;
    while (p!= NULL){
        printf("%d * X^%d ",p->x,p->y);
        if (p->next != NULL){
            printf(" + ");
        }
        p=p->next;
    }
    printf("\n");
}

int main(){
    int N;
    scanf("%d",&N);
    polynomiral p= (node*)malloc(sizeof(node));
    p->next=NULL;
    polynomiral rear=p;
    int i;
    for (i = 0; i < N; i++) {
        polynomiral tmp= (node*)malloc(sizeof(node));
        tmp->next=NULL;
        scanf("%d",&tmp->x);
        scanf("%d",&tmp->y);
        rear->next=tmp;
        rear=rear->next;
    }

    scanf("%d",&N);
    polynomiral q= (node*)malloc(sizeof(node));
    q->next=NULL;
    rear=q;
    for (i = 0; i < N; i++) {
        polynomiral tmp= (node*)malloc(sizeof(node));
        tmp->next=NULL;
        scanf("%d",&tmp->x);
        scanf("%d",&tmp->y);
        rear->next=tmp;
        rear=rear->next;
    }
    addPolynomiral(p,q);
    multiplicationPolynomiral(p,q);

    return 0;
}

polynomiral addPolynomiral(polynomiral p,polynomiral q){

}


polynomiral multiplicationPolynomiral(polynomiral p,polynomiral q){

}
